import { faker } from "@faker-js/faker";

import { type DndDataType, type TaskComment, TaskPriority, TaskTag } from "./types";

const fakeComment = (count: number): TaskComment[] => {
	const result = [];
	const chineseComments = [
		"这个功能需要进一步优化用户体验",
		"建议采用更简洁的设计方案",
		"已完成基础功能，等待测试反馈",
		"与产品团队讨论后，需要调整交互流程",
		"代码review通过，准备上线",
		"发现了一个边界情况的bug，正在修复",
		"用户反馈很积极，可以考虑扩展功能",
		"性能测试结果良好，符合预期",
		"UI设计稿已确认，开始前端开发",
		"后端接口联调完成，数据流转正常",
	];
	const chineseNames = [
		"张雅琪",
		"李文博",
		"王思雨",
		"陈浩然",
		"刘诗涵",
		"杨明轩",
		"赵欣悦",
		"周志强",
		"吴美琳",
		"郑凯文",
		"黄雨婷",
		"徐俊杰",
		"孙晓丽",
		"马建华",
		"朱雅娟",
	];

	for (let index = 0; index < count; index += 1) {
		result.push({
			username: chineseNames[Math.floor(Math.random() * chineseNames.length)],
			avatar: faker.image.avatarGitHub(),
			content: chineseComments[Math.floor(Math.random() * chineseComments.length)],
			time: faker.date.past(),
		});
	}
	return result;
};

const fakeAttachment = (count: number) => {
	const result = [];
	for (let index = 0; index < count; index += 1) {
		result.push(faker.image.urlPicsumPhotos());
	}
	return result;
};

const fakeAssignee = (count: number) => {
	const result = [];
	for (let index = 0; index < count; index += 1) {
		result.push(faker.image.avatarGitHub());
	}
	return result;
};

const fakeTag = (count: number) => {
	const uniqueArray = [];
	const set = new Set();

	while (uniqueArray.length < count) {
		const randomElement = faker.helpers.enumValue(TaskTag);
		if (!set.has(randomElement)) {
			uniqueArray.push(randomElement);
			set.add(randomElement);
		}
	}

	return uniqueArray;
};

export const initialData: DndDataType = {
	tasks: {
		"task-1": {
			id: "task-1",
			title: "优化用户登录体验",
			reporter: faker.image.avatarGitHub(),
			priority: TaskPriority.LOW,
			tags: [],
			comments: [],
			attachments: [],
		},
		"task-2": {
			id: "task-2",
			title: "设计新版首页布局",
			reporter: faker.image.avatarGitHub(),
			assignee: fakeAssignee(1),
			date: faker.date.future(),
			priority: TaskPriority.HIGH,
			tags: fakeTag(3),
			comments: fakeComment(1),
			attachments: fakeAttachment(4),
		},
		"task-3": {
			id: "task-3",
			title: "实现商品搜索功能",
			reporter: faker.image.avatarGitHub(),
			assignee: fakeAssignee(2),
			priority: TaskPriority.MEDIUM,
			date: faker.date.future(),
			tags: fakeTag(2),
			comments: fakeComment(2),
			attachments: [],
		},
		"task-4": {
			id: "task-4",
			title: "构建用户评价系统",
			reporter: faker.image.avatarGitHub(),
			assignee: fakeAssignee(3),
			priority: TaskPriority.MEDIUM,
			tags: fakeTag(3),
			date: faker.date.future(),
			description:
				"开发完整的用户评价功能，包括评分、评论、图片上传等功能。需要考虑评价的真实性验证机制，防止恶意刷评。同时要设计合理的评价展示逻辑，帮助其他用户更好地了解商品质量。评价数据需要支持多维度统计分析。",
			attachments: [],
			comments: fakeComment(3),
		},
		"task-5": {
			id: "task-5",
			title: "移动端适配优化",
			reporter: faker.image.avatarGitHub(),
			priority: TaskPriority.HIGH,
			assignee: fakeAssignee(4),
			tags: fakeTag(4),
			date: faker.date.future(),
			description:
				"全面优化移动端用户体验，确保在不同尺寸屏幕上的完美展示。重点关注触摸交互、页面加载速度、用户操作流程简化。",
			attachments: [],
			comments: fakeComment(4),
		},
		"task-6": {
			id: "task-6",
			title: "数据统计分析仪表板",
			reporter: faker.image.avatarGitHub(),
			priority: TaskPriority.LOW,
			assignee: fakeAssignee(5),
			tags: fakeTag(5),
			date: faker.date.future(),
			description:
				"构建综合性数据分析仪表板，为运营团队提供实时的业务指标监控。包括用户行为分析、销售趋势图表、性能监控等模块。需要支持自定义报表生成和数据导出功能。",
			attachments: fakeAttachment(5),
			comments: fakeComment(4),
		},
	},
	columns: {
		"column-1": {
			id: "column-1",
			title: "待办事项",
			taskIds: ["task-1", "task-2", "task-3"],
		},
		"column-2": {
			id: "column-2",
			title: "进行中",
			taskIds: ["task-4", "task-5"],
		},
		"column-3": {
			id: "column-3",
			title: "已完成",
			taskIds: ["task-6"],
		},
	},
	columnOrder: ["column-1", "column-2", "column-3"],
};
